fix(sync): notification can get stuck. - #20363
Conversation
criticalAY
left a comment
There was a problem hiding this comment.
Logically seems correct to me but can you add tests to verify this, add tests to see if you can reproduce the error there and your solution later should pass the tests.
Added Robolectric test for SyncMediaWorker that simulates an error after the foreground notification is active and verifies the notification is always cancelled from the finally block. |
To avoid the error notification being cancelled, can we use separate notification IDs for failed cases so the finally block only cancels the progress notification?? @lukstbit I’ve tried multiple times to reproduce the original stuck-notification bug, but I haven’t been able to so far. The added test covers the same scenario (error after the notification is shown) and it passes with the fix, i'll keep testing on a real device and if I’m able to reproduce it i'll share a video here. |
lukstbit
left a comment
There was a problem hiding this comment.
I don't think different notifications ids would fix this, feels something related to the WorkManager system itself when the worker is cancelled(maybe due to the constraint). I propose to just add a call to notificationManager?.cancel(NotificationId.SYNC_MEDIA) just before the cancelMediaSync(CollectionManager.getBackend()) line in the catch that deals with the coroutine cancellation and see how this goes in production.
The test should be removed, it mocks so much that it isn't real life behavior.
Got it, thanks for the explanation and suggestion. |
|
It'd be great to see this fixed! Drafting this until it's ready. Please mark it as ready for review once a reproduction case is found (even if this is just a patch to the code). In addition:
|
@david-allison, I still haven’t been able to reproduce the stuck-notification behavior naturally on my device, but the stuck notification is likely caused by WorkManager cancelling the sync worker due to constraints, as lukstbit mentioned also. (network drop, battery saver, OEM killing the app etc.) When this happens, the worker throws a The fix adds an explicit |
|
Hello 👋, this PR has had no activity for more than 2 weeks and needs a reply from the author. If you think this is a mistake please comment and ping a maintainer to get this merged ASAP! Thanks for contributing! You have 7 days until this gets closed automatically |
lukstbit
left a comment
There was a problem hiding this comment.
Ok.
The cancellation of the worker is the only path we don't cover for notification handling so I think it's worth to add the code for logging and as an attempt of the fix.
14d78a1 to
f5a8a3a
Compare
|
thanks so much!! |
|
@david-allison The test you added is failing and it doesn't look right, you're throwing an exception on a method that is called before the call you are checking for. |
@lukstbit I believe I re-added the test in my force push (given the above message), apologies. If this isn't the same test, please flag it, I do not recall writing it. |
f5a8a3a to
6216763
Compare
|
@Giyutomioka-SS can you clarify which parts of the issue this pr doesn't solve? or should #19830 be marked as fixed? |
|
@LUwUcifer, this PR covers the normal sync completion/error paths but doesn’t fully handle the WorkManager worker cancellation path yet, so that’s where the notification could still get stuck. I couldn’t reproduce this, could you try and see if it happens on your side? |
|
Nope, should add "can't reproduce" tag to #19830 |
Purpose / Description
This change makes sure the sync notifications (“Syncing…” and “Syncing media…”) are always removed, even when sync is cancelled or fails with an error. Previously they were only cleared on a clean, successful sync, so in rare cases they could stay stuck for a long time.
Fixes
Approach
When the main sync worker and the media sync worker finish, we now always call notificationManager.cancel(...) from a finally block. This runs no matter how the work ends: success, error, or when the user presses the Cancel button on the notification, so the ongoing sync notifications are reliably dismissed.
How Has This Been Tested?
Verified that both sync workers now always cancel their notifications from a finally block on all exit paths (success, error, and user cancel), and that the project builds and ktlint passes locally.
but i haven’t been able to reliably reproduce the original stuck-notification issue, so I’d really appreciate it if someone who has seen it could help confirm the fix end to end, or share the exact steps to reproduce it.
Related:
Checklist
Please, go through these checks before submitting the PR.